#include<stdlib.h>
#include<string.h>

char *decodeMessage(char *key, char *message)
{
    int n = 0;
    char *apl = (char *)calloc(26, sizeof(char));
    int *aplflag = (int *)calloc(26, sizeof(int));
    for (int i = 0; i < strlen(key); i++)
    {
        if (key[i] == ' ')
        {
            continue;
        }
        if (aplflag[key[i] - 'a'] == 0)
        {
            apl[n++] = key[i];
            aplflag[key[i] - 'a'] = 1;
        }
        if (n == 26)
        {
            break;
        }
    }
    for (int j = 0; j < strlen(message); j++)
    {
        if (message[j] == ' ')
        {
            continue;
        }
        else
        {
            for (int k = 0; k < 26; k++)
            {
                if (message[j] == apl[k])
                {
                    message[j] = k + 'a';
                    k = 26;
                }
            }
        }
    }
    return message;
}
